package adt;

import java.util.Random;

import kernel.CPU;
import kernel.CPU.Request;

/**
 * 
 * @author Aaron Fung
 *		   Chris Ren
 * @version 1.0	
 */
public class UIProcess extends CPUprocess {

	/**
	 * Construct that takes an int as it's process ID.
	 * @param the_pid the process id.
	 */
	public UIProcess(final int the_pid) {
		super(the_pid);
	}
	
	/**
	 * Output to the screen. 
	 * The process stop for 50 ms.
	 */
	@Override
	public void proceessoutput() 
	{
		try {
			Thread.sleep(50);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
//		System.out.println(this.toString() + " is runing... Step: " + getPCB().getStep() + 
//				" Generates Interrupt at: " + getPCB().getEvent());
	} 



	@Override
	public String toString() {
		return "PID: " + getPid() + "     Type: UI Process\n";
	}

	/**
	 * Randomly return a KEYBOARD/VIDEO/DISK request.
	 */
	@Override
	public Request getRequest() {
		Random int_gen = new Random();
		int_gen.nextInt(3);
		switch(int_gen.nextInt(3))
		{
		case 0:
			return CPU.Request.KEYBOARD_REQUEST;
		case 1:
			return CPU.Request.VIDEO_REQUEST;
		case 2:
			return CPU.Request.DISK_REQUEST;
		default:
			return CPU.Request.KEYBOARD_REQUEST;
		}
		
		
	}

}
